const BASE_URL = 'http://123.207.32.32:9001/'
const LOGIN_BASE_URL = 'http://123.207.32.32:3000/'
// http://112.124.28.77:3000/
// http://123.207.32.32:9001/
class Request {
    constructor(baseURL,authHeader = {}){
        this.baseURL = baseURL
        this.authHeader = authHeader
    }
    request(url, method, params, isAuth= false ,header = {}) {
        const finalHeader = isAuth? {...this.authHeader,...header } : header
        return new Promise((resolve, reject) => {
            wx.request({
                url: this.baseURL + url,
                method,
                header:finalHeader,
                data: params,
                success: res => {
                    resolve(res.data)
                },
                fail: err => {
                    console.log('请求失败!');
                    reject(err.data)
                }
            })
        })
    }
    get(url, params,isAuth , header) {
        return this.request(url, 'GET', params, isAuth, header)
    }
    post(url, data, isAuth, header) {
        return this.request(url, 'POST', data, isAuth, header)
    }
}

export default new Request(BASE_URL)
const token = wx.getStorageSync('TOKEN-KEY')
const LoginRequest = new Request(LOGIN_BASE_URL,{
    token
})
export {
    LoginRequest
}